package com.itqf.ibatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * projectName: mybatis2103
 *
 * @author: 赵伟风
 * time: 2021/6/23 17:24
 * description:
 */
public class UseIbatisSelect {

    public static void main(String[] args) throws Exception{

        //1.加载核心配置文件
        InputStream stream = Resources.getResourceAsStream("mybatis_config.xml");

        //2.创建一个SqlSessionFactoryBuilder
        SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();

        //3.创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = factoryBuilder.build(stream);

        //4.创建SqlSession
        SqlSession session = sqlSessionFactory.openSession();
        //SqlSession sqlSession = sqlSessionFactory.openSession(false);

        //5.sqlsession进行数据库操作
        //ibatis进行SQL语句的方式
        //sqlsession.方法(namespace.标签id,参数)
        Object obj = session.selectOne("com.itqf.mybatis.selectMenuById", 1);
        System.out.println("obj = " + obj);
//        session.selectList(, );
//
//        session.insert(, );
//        session.delete(, );
//        session.update()

        //Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itqf.mybatis.selectMenuById
        //1.看看字符串是不是写错了!
        //2.mybatis核心配置文件没有引入mapper.xml

        //6.进行资源数据库事务提交和资源关闭
        //session.commit();
        session.close();


    }
}
